const modalColor = '#5271FF'
var message = {
  // 短提示
  toast (title, type = 'text') {
    if (title.length > 15) {
      console.error('toast长度超过15个字符,当前长度为' + title.length)
      return
    }
    var icon = 'none'
    if (type) {
      switch (type) {
        case 'text':
          icon = 'none'
          break
        case 'suc':
          icon = 'success'
          break
        case 'err':
          icon = 'error'
          break
      }
    }
    uni.showToast({
      title,
      icon
    })
  },
  // 弹窗提示(有取消按钮和确认)

  confirm (title, confirmColor) {
    return new Promise((res, rej) => {
      uni.showModal({
        title,
        cancelColor: '#b6b6b6',
        confirmColor: confirmColor || modalColor,
        success: (result) => {
          if (result.cancel) {
            rej(result)
          } else if (result.confirm) {
            res(result)
          }
        }

      })
    })
  },
  // 弹窗提示(没有取消按钮)
  async message (content, confrimText) {
    return new Promise((res) => {
      uni.showModal({
        title: '提示',
        content,
        showCancel: false,
        confirmColor: modalColor,
        success: (result) => {
          res(result)
        }
      })
    })
  }
}
module.exports = message

